<?php !defined("IN_SYSTEM") && exit("ACCESS DENY");?>
{template header}
{template top}
<div id="uc">
{template uc/left}
<div id="uc_main">
	<div class="uc_tab">
	<ul>
	<li>{if !$action}<span class="on">所有订单</span>{else}<a href="{url home.php?m=myorder}">所有订单</a>{/if}</li>
	</ul>
	</div>
	
	<div id="uc_contain">
	{if !$action}
	<form action="{echo url('home.php?m=myorder')}" method="POST" class="uc_search">
			搜索订单: <input type="text" name="search_field" class="txt" size="32" onclick="if(this.value=='输入订单号或手机'){ this.value='';}" onblur="if(this.value==''){ this.value='输入订单号或手机';}" id="search_field" value="{if $field}{$field}{else}输入订单号或手机{/if}"/>
				<input type="submit" class="button" value="{$lang['search']}"/>
				</form>
				<table class="uc_table" >
				<tr>
					<th  width="100">订单类型/订单号</th><th>订单商品</th><th width="100">收货人</th><th  width="110">订单金额/支付方式</th><th width="70">订单时间</th><th width="70">订单状态</th><th width="70">{$lang['operation']}</th>
					</tr>
			{loop $datas $data}
				<tr id="tr{$data['pid']}">
				<td><div>{$lang[$data['type']]}</div><a href="{url home.php?m=myorder&a=view&id=$data[txnid]}" target="_blank">{$data['txnid']}</a></td>
				<td><ul class="uorderr" style="text-align: right; font-size:13px;">
				{php $num=0;}
				{loop $caidans[$data['txnid']] $c}
				{php if(!$c['comment'])$num++;}
				<li>{$c['title']}({$c['price']}元) X {$c['qty']}</li>
				{/loop}
				</ul></td>
				<td><div>{$data['firstname']}</div>{$data['phone']}</td>
				<td>￥{$data['gross']}<br/>{$lang[$data['payment_type']]}</td>
				<td style="color:#999">{gdate('Y/m/d',$data['created'])}<br/>{gdate('H:i:s',$data['created'])}</td>
				<td>
				{if $data['type']!='food'}
				{$status[$data['status']]}
				{else}
				{$orderstatus[$data['status']]}
				{/if}</td>
				<td>
				{if $data['status']==4}
				<a href="javascript:;" onclick="order_status({$data[txnid]})">[确认收货]</a><br/>
				{/if}
				<a href="{url home.php?m=myorder&a=view&id=$data[txnid]}" target="_blank" >[查看]</a><br/>
				{if $data['status']<1}
				{if  $data['type']=='food'}
				<a href="{url home.php?m=myorder&a=edit&id=$data[txnid]}" target="_blank" >[调整]</a><br/>
				{/if}
				{if $data['payment_type']!='cod'}
				<a href="{url payment.php?f=pay&id=$data[txnid]}"  onclick="return payment_form(this.href);">[去支付]</a><br/>
				{/if}
				<a href="javascript:;" onclick="order_cancel({$data[txnid]})" >[取消]</a><br/>
				{/if}
				{if $data['status']==7 && $num>0}
				<a href="{url home.php?m=dianpin&id=$data[txnid]}" target="_blank" >[评价]</a><br/>
				{/if}
				{if $data['status']<7 && $data['type']=='food'}<a href="{url home.php?m=myorder&a=quick&id=$data[txnid]}" title="催促一下店主，让他快点" target="_blank">[催店主]</a>{/if}</td>
				</tr>
			{/loop}
				</table>
				<script type="text/javascript">
				function payment_form(u){
					var edit = art.dialog({
					    title: '<?php echo $lang['goto_pay']?>',
					    fixed: true, 
					    width:350,
					    height:200,
					    padding:'10px 0 0',
					    cssname:'uc_gotopay',
					    content: '<iframe src="'+u+'" frameborder="0" style="width:350px;height:200px;overflow:hidden;" />'
						});
					return false;
				}
				function order_cancel(id){
					if(!confirm('确定取消该交易?')){
						return false;
					}
					$.getJSON("home.php?m=myorder&a=cancel&id="+id+'&tm='+Math.random(),'',function(data){
						if(data.s==true){
							if(data.m){alert(data.m);}
							document.location.reload();
						}else{
						}
						});
					return false;
				}
				</script>
				<?php echo $pager;?>
	{/if}
	{if $action=='view'}
	<div class="mt"><h3>商品信息</h3><div class="fr">{if $data['type']=='pointpay'}<a href="{url home.php?f=point&a=recharge}" target="_blank">点击再购买</a>{else}如需再次购买订单中的商品，您可以<a href="">将全部商品放入购物车</a>{/if}</div></div>
	
	<table width="100%" class="uc_tableb winfo"><tbody>
	{if $data['type']=='pointpay'}
	<tr><th colspan="6">购买积分</th></tr>
	{if $data['amount']}
	<tr><td  colspan="6">{$setting[$_G['settings']['point']['pointuse']]['title']}：{$data['amount']}</td></tr>
	{else}
	<tr><td colspan="6" >-</td></tr>
	{/if}
	{else}
						<tr>
							<th width="10%">商品编号</th>
							<th width="45%">商品名称</th>
							<th width="10%">商品单价</th>
							<th width="10%">赠送积分</th>
							<th width="10%">商品数量</th>
							<th width="100">操作</th>
						</tr>
						{loop $goods $good}
						<tr>
						    <td>{$good['pid']}</td>
						    <td>{$good['title']}</td>
						    <td><strong>￥{price($good['price'])}</strong></td>
						    {php $goodsp+=$good['price'];}
						    <td>{$good['credit']}</td>
						    <td>{$good['qty']}</td>
						    <td>{$good['sku']}</td>
						</tr>
						{/loop}
						{if empty($goods)}
						<tr><td colspan="6" >-</td></tr>
						{/if}
	{/if}	
	</tbody></table>
					    		  
			  
	<table class="uc_tableb">
		<tbody><tr><th align="left"><strong>订单信息</strong></th></tr>
		<tr><td><div>
		订单编号：{$data['txnid']}<br>
		支付方式：{$lang[$data['payment_type']]}<br>
		{if $data['shipping_type']}配送方式：{$lang[$data['shipping_type']]}<br>{/if}
		下单时间：{gdate('Y-m-d H:i:s',$data['created'])}<br>
		{if $data['trade_no']}{$lang[$data['payment_type']]}订单号：{$data['trade_no']}<br>{/if}
		</div></td></tr>
		<tr><td><div>
			<strong>收货人信息</strong><br>
			收货人姓名：{$data['firstname']}<br>
			地址：{$data['street1']} {$data['street']}&nbsp; &nbsp;邮编：{$data['zip']}<br>
			固定电话：{$data['tel']}  
			手机号码：{$data['phone']}      <br>
			电子邮件：{$data['mail']}
		</div></td></tr>
		<tr><td><div>
			<strong>订单备注</strong><br>
			{$data['data']}
		</div></td></tr>
		<tr><td><div>
			<strong>结算信息</strong><br>
商品金额：{price($goodsp)}元 + 
运费：{price($data['shipping_cost'])}元
{if $data['amount']}
 + 积分充值：{price($data['amount']*$ratio)}元
{/if} 

 = 
<strong class="h1">订单总金额：<span class="red">{$data['gross']}元</span></strong>
		</div></td></tr> 
		</tbody>
	</table>	
	{/if}			
	{if $action=='edit'}
	<form action="{url home.php?m=myorder&a=save}" id="cart" method="post" name="cart">
			<input type="hidden" value="{$id}" name="id"/>
			<div style="width:500px;">
			<div class="catitle"><span class="cart1" style="width:40%">菜名</span><span style="float:left;width:15%;">单价</span><span class="cart2">数量</span><span class="cart3">总价</span></div>
			<ul id="caul">
			{loop $products $cart}
			<li class="cali" id="cali{$cart['pid']}"><span class="cart1" style="width:40%">{$cart['title']}</span><span style="float:left;width:15%;">{$cart['price']}</span><span class="cart2"><a href="javascript:;" onclick="crease({$cart['pid']},0)">-</a><font id="qty{$cart['pid']}">{$cart['qty']}</font><a href="javascript:;" onclick="crease({$cart['pid']},1)">+</a></span><span class="cart3"><font id="price{$cart['pid']}">{echo price($cart['price']*$cart['qty']);}</font></span><span class="cart4" onclick="crease({$cart['pid']},3)" title="删除">x</span></li>
			
			{/loop}
			</ul>
			<div id="catdiv">
			<span>外送费 <span id="shippfee" >{echo price($orders['shipping_cost']);}</span> 元</span>
			</div>
			<div id="catdiv" style="margin-bottom:15px;">
			<span style="float:left;display:none;"><input style="padding:2px" class="input" value="请输入菜单编号" onclick="if(this.value=='请输入菜单编号')this.value='';" onblur="if(this.value=='')this.value='请输入菜单编号';" size="22" name="addcai" id="addcai"/><input style="" type="button" value="加菜" onclick="return crease(2,2);"/></span>
			<span>合计 <span id="catotal" >{echo price($orders['gross']);}</span> 元</span> </div>
			</div>
			
			<input type="hidden" name="shopid" value="{$id}"/>
			<div ><label>联系电话:</label><input type="text" class="input" name="phone" value="{$orders['phone']}" size="45"/></div>
			<div ><label>送餐地址:</label><input type="text" class="input" name="address" value="{$orders['street']}" size="45" /></div>
			<div><label>送餐时间:</label><select id="deliver_time" name="deliver_time"><option selected="selected" value="">尽快送出</option>
	<option value="22:45:00">22:45:00</option>
	<option value="23:00:00">23:00:00</option>
	<option value="23:15:00">23:15:00</option>
	</select></div>
	
		<div class="clear">
	      外送备注(选填):
	<div id="cartextra">
	    <span onclick="cartextra(this)">么零钱</span>
	    <span onclick="cartextra(this)">不要葱姜蒜</span>
	    <span onclick="cartextra(this)">不吃辣</span>
	    <span onclick="cartextra(this)">辣一点</span>
	    <span onclick="cartextra(this)">多加米</span>
	    <span onclick="cartextra(this)">囧</span>
	    <span onclick="cartextra(this)">谢谢:)</span>
	</div>
	<div class="text">
	    <textarea tabindex="5" name="note" id="extra"  cols="54">{$orders['shipping_note']}</textarea>
	    <div class="checkout_btn_wrapper">
	      <button class="button"  type="submit" id="checkout_btn">保存订单</button>
	    </div>
	</div>
	<div class="clear"></div>
	    </div>
			
			
			</form>
	<script>
			function update_total(obj){
				var total = parseFloat($('#catotal').val()) - parseFloat($(obj).attr('ref')) + parseFloat(obj.value);
				$('#catotal').val(money(total));
				$(obj).attr('ref',obj.value);
			}
			function cartextra(obj){
				$(obj).attr('onclick','dcartextra(this)');
				$('#extra').append(' '+$(obj).html());
			}
			function dcartextra(obj){
				$(obj).attr('onclick','cartextra(this)');
				var a=$('#extra').html();
				$('#extra').html(a.replace(' '+$(obj).html(),''));
			}
			function crease(id,t){
				var txnid = {$id};
				if(t==1){
					var a='increase';
				}else if(t==2){
					var id = $('#addcai').val();
					var a='add';
				}else if(t==3){
					if(!confirm('确定从订单中删除此道菜?')){return false;}
					var a='clear';
				}else{
					var a='decrease';
				}	
				$.getJSON("home.php?m=myorder&a="+a+"&id="+id+'&txnid='+txnid+'&tm='+Math.random(),'',function(data){
					if(data.s==true){
						if(t==2){
							$('#cali'+id).remove();
							$('#caul').append('<li class="caul" id="cali'+id+'"><span class="cart1" style="width:40%">'+data.h+'</span><span style="float:left;width:15%;">'+data.up+'</span><span class="cart2"><a href="javascript:;" onclick="crease('+id+',0)">-</a><font id="qty'+id+'">'+data.q+'</font><a href="javascript:;" onclick="crease('+id+',1)">+</a></span><span class="cart3"><font id="price'+id+'">'+money(data.p)+'</font></span><span class="cart4" onclick="crease('+id+',3)" title="删除">x</span></li>');
							$('.cart').show();
						}else if(t==3){
							if(data.t==0){
								$('#caul').html('<li></li>');
								$('.cart').hide();
								//$('#catdiv').remove();
								return ;
							}else{
								$('#cali'+id).remove();
							}	
						}else{
						$('#qty'+id).html(data.q);
						$('#price'+id).html(money(data.p));
						}
						$('#catotal').html(money(data.t));
					}else{
						alert(data.m);
					}
					});
			}
			function checkout(u){
				var content = $('.checkout').html();
				$('.checkout').html('');
				var edit = art.dialog({
				    title: '确认下单',
				    lock: true,
				    fixed: true, //C=G.DW
				    padding:'0 0 0 15px',
				    cssname:'uc_editfrind',
				    content: content,
				    closeFn: function () {
				    	$('.checkout').html(content);
				    }
					});
				
				return false;
			}
			</script>
	
			
	
	
	
	{/if}
			
	</div>
</div>
</div>
{template footer}